// interactionRoutes.js - 用户互动路由配置
const express = require('express');
const router = express.Router();
const { authMiddleware } = require('../utils/auth');
const LikeController = require('../controllers/LikeController');
const FavoriteController = require('../controllers/FavoriteController');
const CommentController = require('../controllers/CommentController');
const FollowController = require('../controllers/FollowController');

/**
 * 互动相关路由 - 所有接口都需要认证
 */

// ========== 点赞相关接口 ==========

/**
 * 点赞视频
 * POST /api/interactions/like
 * @body {number} videoId - 视频ID
 */
router.post('/like', authMiddleware, LikeController.likeVideo);

/**
 * 取消点赞
 * POST /api/interactions/unlike
 * @body {number} videoId - 视频ID
 */
router.post('/unlike', authMiddleware, LikeController.unlikeVideo);

/**
 * 检查点赞状态
 * GET /api/interactions/like/status?videoId=1
 * @query {number} videoId - 视频ID
 */
router.get('/like/status', authMiddleware, LikeController.checkLikeStatus);

/**
 * 获取用户点赞的视频列表
 * GET /api/interactions/like/list?page=1&pageSize=10
 * @query {number} page - 页码
 * @query {number} pageSize - 每页数量
 */
router.get('/like/list', authMiddleware, LikeController.getUserLikedVideos);

// ========== 收藏相关接口 ==========

/**
 * 收藏视频
 * POST /api/interactions/favorite
 * @body {number} videoId - 视频ID
 */
router.post('/favorite', authMiddleware, FavoriteController.favoriteVideo);

/**
 * 取消收藏
 * POST /api/interactions/unfavorite
 * @body {number} videoId - 视频ID
 */
router.post('/unfavorite', authMiddleware, FavoriteController.unfavoriteVideo);

/**
 * 检查收藏状态
 * GET /api/interactions/favorite/status?videoId=1
 * @query {number} videoId - 视频ID
 */
router.get('/favorite/status', authMiddleware, FavoriteController.checkFavoriteStatus);

/**
 * 获取用户收藏的视频列表
 * GET /api/interactions/favorite/list?page=1&pageSize=10
 * @query {number} page - 页码
 * @query {number} pageSize - 每页数量
 */
router.get('/favorite/list', authMiddleware, FavoriteController.getUserFavoriteVideos);

// ========== 评论相关接口 ==========

/**
 * 创建评论
 * POST /api/interactions/comments
 * @body {number} videoId - 视频ID
 * @body {string} content - 评论内容
 * @body {number|null} parentId - 父评论ID（回复评论时使用）
 */
router.post('/comments', authMiddleware, CommentController.createComment);

/**
 * 删除评论
 * DELETE /api/interactions/comments/:commentId
 * @param {number} commentId - 评论ID
 */
router.delete('/comments/:commentId', authMiddleware, CommentController.deleteComment);

/**
 * 获取视频评论列表
 * GET /api/interactions/comments/:videoId?page=1&pageSize=10
 * @param {number} videoId - 视频ID
 * @query {number} page - 页码
 * @query {number} pageSize - 每页数量
 */
router.get('/comments/:videoId', CommentController.getVideoComments);

// ========== 关注相关接口 ==========

/**
 * 关注用户
 * POST /api/interactions/follow
 * @body {number} userId - 目标用户ID
 */
router.post('/follow', authMiddleware, FollowController.followUser);

/**
 * 取消关注
 * POST /api/interactions/unfollow
 * @body {number} userId - 目标用户ID
 */
router.post('/unfollow', authMiddleware, FollowController.unfollowUser);

/**
 * 检查关注状态
 * GET /api/interactions/follow/status?userId=1
 * @query {number} userId - 目标用户ID
 */
router.get('/follow/status', authMiddleware, FollowController.checkFollowStatus);

module.exports = router;